package wc.servicelet; /**
 * @ClassName:${NAME}
 * @Author: 鹿建文
 * @Date: 2022/4/7  - 15:52
 * @Describe:
 */

import wc.Service.AdminService;
import wc.Service.Impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(urlPatterns = "/updatePassword")
public class UpdatePasswordServlet extends HttpServlet {
    private AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String oldPassword = request.getParameter("oldPassword");
        String newPassword = request.getParameter("newPassword");
        System.out.println(oldPassword + "**" + newPassword);
        boolean res = false;
        try {
            res = adminService.updatePassword(1001, oldPassword, newPassword);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (res){
            response.sendRedirect("index.html");
        } else {
            response.sendRedirect("erro.html");
        }
    }
}
